package com.sqnu.util;

import com.sqnu.javabean.User;
import mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UserMapperTest {
    SqlSession session;
    UserMapper mapper;

    @Before
    public void before() {
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        session = factory.openSession(true);
        mapper = session.getMapper(UserMapper.class);

    }

    @After
    public void after() {
        session.close();
    }

    @Test
    public void selectAll(){
        for (User user : mapper.selectAll()) {
            System.out.println(user);
        }
    }
    @Test
    public void updateUser(){
        User user = new User();
        user.setUid(1);
        user.setUsername("张三");
        mapper.updateUser(user);
    }
    @Test
    public void deleteByArray(){
        int[] array={6,7,8,9};
        mapper.deleteByArray(array);
    }
}